package com.hmall.cart.domain.dto;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        List<Student> students = new ArrayList<>();
        students.add(new Student("刘亚飞", 0, 150));
        students.add(new Student("孙丹", 1, 200));
        students.add(new Student("武汉力拓中用机械有限公司", 1, 50));
        students.add(new Student("苏州礼义信机械制造有限公司", 1, 30));
        // 使用Stream API排序
        List<Student> sortedStudents = students.stream()
                .sorted(Comparator.comparing(Student::getAge))// 按年龄升序) // 按成绩降序
                .sorted(Comparator.comparing(Student::getScore).reversed())
                .collect(Collectors.toList());
// 输出排序后的结果
        sortedStudents.forEach(student -> System.out.println(student.getName() + ", " + student.getAge() + ", " + student.getScore()));
        System.out.println("---------------------------------------------------");

        List<Student> sortedStudents2 = students.stream()
                .sorted(Comparator.comparing(Student::getAge).reversed()
                        .thenComparing(Student::getScore).reversed())
                .collect(Collectors.toList());

        sortedStudents2.forEach(student -> System.out.println(student.getName() + ", " + student.getAge() + ", " + student.getScore()));

    }
}

class Student {
    private String name;
    private int age;
    private int score;

    public Student(String name, int age, int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public int getScore() {
        return score;
    }
}
